﻿using System.Threading;
using System.Threading.Tasks;

namespace ESRI.ArcGIS.Client.Tasks.Async
{
    public static partial class GeoprocessorExtensions
    {
        #region GetServiceInfo

        /// <summary>
        /// Gets the Geoprocessor service information GPServiceInfo
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        public static Task<GPServiceInfoTaskResult> GetServiceInfoTaskAsync(this Geoprocessor task)
        {
            return GetServiceInfoTaskAsync(task, CancellationToken.None);
        }

        /// <summary>
        /// Gets the Geoprocessor service information GPServiceInfo
        /// </summary>
        /// <param name="task"></param>
        /// <param name="cancellationToken">Cancellation token for cancelling task.</param>
        /// <returns></returns>
        public static Task<GPServiceInfoTaskResult> GetServiceInfoTaskAsync(this Geoprocessor task,
            CancellationToken cancellationToken)
        {
            return task.HandleTask<Geoprocessor, GPServiceInfoEventArgs, GPServiceInfoTaskResult>(
                t => t.GetServiceInfoAsync(),
                (t, e) => t.GetServiceInfoCompleted += e,
                (t, e) => t.GetServiceInfoCompleted -= e,
                e => new GPServiceInfoTaskResult(e),
                cancellationToken);
        }

        #endregion

    }
}


